package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.*;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Setter
@Getter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties("handler") //handler属性不转换成json
public class Travel extends BaseDomain{

    public static final Integer STATE_REFUSE = -1; //拒绝
    public static final Integer STATE_TEMP = 0; //草稿
    public static final Integer STATE_WAIT = 1; //待审核
    public static final Integer STATE_RELEASE = 2; //审核通过

    private String title;

    //旅游时间
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    private Date travelTime;
    //人均消费
    private String perExpends;

    private Integer days;
    //与xx亲人旅游
    private Integer person=1;

    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    private Date createTime;
    //发布时间
    private Date releaseTime;

    private Boolean isPublic=false; //默认不公开


    private String coverUrl;
    //最后更新时间
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    private Date lastUpdateTime;

    private Integer state=STATE_TEMP;
    //作者
    private User author;
    //地点
    private Region place;

    //游记内容
    private TravelContent travelContent;




    public String getStateName() {
        String str="草稿";
        if (state==STATE_REFUSE) {
            return str="拒绝";
        }else if (state==STATE_WAIT) {
            return str="待审核";
        }else if (state==STATE_RELEASE) {
            return str="审核通过";
        }
        return str;
    }


    /*
    <option value="1">一个人的旅行</option>
    <option value="2">和父母</option>
    <option value="3">和朋友</option>
    <option value="4">和同事</option>
    <option value="5">和爱人</option>
    <option value="6">和驴友</option>
     */

    public String getPersonName() {
        String str="一个人的旅行";
        if (person==2){
            return str="和父母";
        }else if (person==3){
            return str="和朋友";
        }else if (person==4){
            return str="和同事";
        }else if (person==5){
            return str="和爱人";
        }else if (person==6){
            return str="和驴友";
        }
        return str;
    }

    //设置推荐json字符串
    public String getJson() {
        Map<String, Object> map = new HashMap<>();
        map.put("travelId", id);
        map.put("travelTitle", title);
        map.put("travelCoverUrl", coverUrl);
        return JSONUtil.toJSONString(map);
    }
}